/*     */ package com.zimbra.cs.mailclient.imap;
/*     */ 
/*     */ import com.zimbra.cs.mailclient.MailClient;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ListIterator;
/*     */ import javax.security.auth.login.LoginException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ImapClient
/*     */   extends MailClient
/*     */ {
/*     */   private String mailbox;
/*     */   private IDInfo idInfo;
/*  33 */   private static final String[] USAGE = { "Usage: java " + ImapClient.class.getName() + " [options] hostname", "  -p port  : port to use (default is 143 or 993 for SSL)", "  -u user  : authentication id to use", "  -z user  : authorization id to use", "  -w pass  : password to use", "  -r realm : authentication realm", "  -m mech  : SASL mechanism to use (\"login\" for IMAP LOGIN)", "  -k #     : Minimum QOP to use (0=auth, 1=auth-int, 2=auth-conf)", "  -l #     : Maximum QOP to use (0=auth, 1=auth-int, 2=auth-conf)", "  -s       : enable IMAP over SSL (imaps)", "  -t       : enable IMAP over TLS", "  -f mbox  : select specified mailbox", "  -d       : enable debug output", "  -q       : enable silent mode", "  -i id    : send ID info (name=value,...)", "  -h       : print this help message" };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected ImapClient()
/*     */   {
/*  54 */     super(new ImapConfig());
/*     */   }
/*     */   
/*     */   protected void authenticate() throws LoginException, IOException
/*     */   {
/*  59 */     if (this.idInfo != null) {
/*  60 */       getImapConnection().id(this.idInfo);
/*     */     }
/*  62 */     super.authenticate();
/*  63 */     if (this.mailbox != null) {
/*  64 */       getImapConnection().select(this.mailbox);
/*     */     }
/*     */   }
/*     */   
/*     */   protected boolean parseArgument(ListIterator<String> args)
/*     */   {
/*  70 */     String arg = (String)args.next();
/*  71 */     if ((arg.equals("-f")) && (args.hasNext())) {
/*  72 */       this.mailbox = ((String)args.next());
/*  73 */       return true; }
/*  74 */     if ((arg.equals("-i")) && (args.hasNext())) {
/*  75 */       parseIDInfo((String)args.next());
/*  76 */       return true;
/*     */     }
/*  78 */     args.previous();
/*  79 */     return super.parseArgument(args);
/*     */   }
/*     */   
/*     */   private void parseIDInfo(String id) {
/*  83 */     if (this.idInfo == null) {
/*  84 */       this.idInfo = new IDInfo();
/*     */     }
/*  86 */     for (String s : id.split(",")) {
/*  87 */       int i = s.indexOf('=');
/*  88 */       if (i > 0) {
/*  89 */         this.idInfo.put(s.substring(0, i), s.substring(i + 1));
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   protected void printUsage(PrintStream ps)
/*     */   {
/*  96 */     for (String line : USAGE) ps.println(line);
/*     */   }
/*     */   
/*     */   protected boolean processCommand(String[] cmdLine) throws IOException
/*     */   {
/* 101 */     ImapConnection ic = getImapConnection();
/* 102 */     String cmd = cmdLine[0];
/* 103 */     if (isMatch(cmd, "SELect")) {
/* 104 */       MailboxInfo mbox = ic.select(cmdLine[1]);
/* 105 */       System.out.printf(">> Selected mailbox: %s\n", new Object[] { mbox });
/* 106 */     } else if (isMatch(cmd, "CAPability")) {
/* 107 */       ImapCapabilities cap = ic.capability();
/* 108 */       System.out.printf(">> Capabilities: %s\n", new Object[] { cap });
/*     */     } else {
/* 110 */       super.processCommand(cmdLine);
/*     */     }
/* 112 */     return true;
/*     */   }
/*     */   
/*     */   protected boolean processShow(String[] cmdLine) throws IOException
/*     */   {
/* 117 */     ImapConnection ic = getImapConnection();
/* 118 */     String arg = cmdLine[1];
/* 119 */     if (isMatch(arg, "CAPability")) {
/* 120 */       System.out.printf(">> Current capabilities: %s\n", new Object[] { ic.getCapabilities() });
/* 121 */     } else if ((isMatch(arg, "MAILbox")) || (isMatch(arg, "MBox"))) {
/* 122 */       System.out.printf(">> Current mailbox: %s\n", new Object[] { ic.getMailboxInfo() });
/*     */     } else {
/* 124 */       return false;
/*     */     }
/* 126 */     return true;
/*     */   }
/*     */   
/*     */   public ImapConnection getImapConnection() {
/* 130 */     return (ImapConnection)this.connection;
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception {
/* 134 */     new ImapClient().run(args);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/imap/ImapClient.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */